﻿using AutoMapper;
using rbac.contracts.Dto.Output;
using rbac.domain.Entity;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using rbac.contracts.Dto.Input;

namespace rbac.contracts
{
    // 将实体类与Dto类建立映射关系
    public class RbacProfile:Profile
    {
        public RbacProfile()
        {
            // 将User类与UserOutput映射上
            CreateMap<User, UserOutput>();

            CreateMap<Role, RoleOutput>();
            
            CreateMap<RoleInput, Role>();
            
            CreateMap<Permission, PermissionOutput>();
            
            CreateMap<PermissionInput, Permission>();
            
            // 将Permission表中的Id字段，映射至PermissionDto中的PermissionId
            CreateMap<Permission, PermissionDto>()
                .ForMember(p=>p.PermissionId,opt=>opt.MapFrom(src=>src.Id));
        }
    }
}
